﻿using Autofac;
using Autofac.Integration.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;

namespace OAOA.Configs
{
    public class AutofacConfig
    {
        public static void Configs()
        {
            var builder = new ContainerBuilder();
            //加载当前程序集
            Assembly controllerAss = Assembly.GetExecutingAssembly();
            //注册所有的Controller
            builder.RegisterControllers(controllerAss).PropertiesAutowired();

            //注册业务层程序集
            Assembly bllAss = Assembly.Load("OA.Service");
            builder.RegisterTypes(bllAss.GetTypes()).AsImplementedInterfaces();

            var container = builder.Build();
            //当mvc创建Controller对象的时候，都是由Autofac为我们创建Controller对象
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

        }
    }
}